﻿@{
    ViewData["Title"] = "添加供应商";
    Layout = null;
}

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Demo</title>
    <!-- 请勿在项目正式环境中引用该 layui.css 地址 -->
    <link href="//unpkg.com/layui@2.9.17/dist/css/layui.css" rel="stylesheet">
</head>
<body>
    <!-- 给容器追加 class="layui-form-pane"，即可显示为方框风格 -->
    <form class="layui-form" action="">
        <div class="layui-form-item">
            <div class="layui-inline">
            <label class="layui-form-label">供应商编码</label>
                
            <div class="layui-input-block">
                <input type="text" name="VendorCode" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
            </div>
                <input type="checkbox" checked lay-skin="switch" lay-filter="switchTest" title="自动生成">
        </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-inline">
            <label class="layui-form-label">供应商名称</label>
            <div class="layui-input-block">
                <input type="text" name="VendorName" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
            </div>
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-inline">
            <label class="layui-form-label">供应商简称</label>
            <div class="layui-input-block">
                <input type="text" name="VendorNick" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
            </div>
        </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-form-item">
            <label class="layui-form-label">供应商等级</label>
            <div class="layui-input-block">
                <select name="VendorLevel" lay-filter="aihao" lay-verify="required">
                    <option value=""></option>
                    <option value="A">优质供应商</option>
                    <option value="B">正常</option>
                    <option value="C">重点关注</option>
                        <option value="D">劣质供应商</option>
                    <option value="E">黑名单</option>
                </select>
            </div>
        </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">供应商评分</label>
            <div class="layui-input-block">
                <input type="text" name="VendorScore" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">供应商电话</label>
            <div class="layui-input-block">
                <input type="text" name="Tel" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
            </div>
        </div>
        
        <div class="layui-form-item">
            <div class="layui-form-item">
                <button class="layui-btn" lay-submit lay-filter="demo2">添加</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
        
    </form>

    <script src="~/Scripts/jquery-3.4.1.min.js"></script>
    <!-- 请勿在项目正式环境中引用该 layui.js 地址 -->
    <script src="//unpkg.com/layui@2.9.17/dist/layui.js"></script>
    <script>
        layui.use(['form'], function () {
            var layer = layui.layer;
            var form = layui.form;
            // 表单提交事件
            form.on('submit(demo2)', function (data) {
                var field = data.field; // 获取表单字段值
                console.log(field); 
                $.ajax({
                    url: "/Meng/AddMdVendor",
                    type: "get",
                    async: true,
                    data: {
                        mdVendor: JSON.stringify(field)
                    },
                    contentType: "application/json",
                    success: res => {
                        if (res == 1) {
                            alert("添加成功")
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(index);
                        }
                        else {
                            console.log(res.code)
                            alert("添加失败")
                        }
                    }
                });
                console.log("1")
                return false; // 阻止默认 form 跳转
            });
        });

    </script>

</body>
</html>